//
//  Mail_GetList_Task.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-31.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Mail_GetList_Task.h"
#import "WebServiceHelper.h"
#import "StringUtil.h"
#import "GDataXMLNode.h"
#import "MailInfoModel.h"

@implementation Mail_GetList_Task

-(void)execute
{
    NSString *ValidateData = [self.params objectForKey:@"ValidateData"];
    NSString *url = [self.params objectForKey:@"url"];
    NSString *wsNamespace = [self.params objectForKey:@"namespace"];
    NSString *userguid = [self.params objectForKey:@"userguid"];
    NSString *boxType = [self.params objectForKey:@"boxType"];
    NSString *KeyWord = [self.params objectForKey:@"KeyWord"];
    NSString *CurrentPageIndex = [self.params objectForKey:@"CurrentPageIndex"];
    NSString *PageSize = [self.params objectForKey:@"PageSize"];
    WebServiceHelper *webserviceHelper = [[WebServiceHelper alloc]initWebServiceWithUrl:url wsNamespace:wsNamespace method:@"Mail_GetList"];
    NSString *ParasXml = @"<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><boxType>%@</boxType><KeyWord>%@</KeyWord><CurrentPageIndex>%@</CurrentPageIndex><PageSize>%@</PageSize></paras>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,boxType,KeyWord,CurrentPageIndex,PageSize];
    ParasXml = [StringUtil filterXmlString:ParasXml];
    [webserviceHelper addParameterForString:@"ValidateData" value:ValidateData];
    [webserviceHelper addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs = webserviceHelper.start;
    [self sendDataRefreshUI:bs];
}

+(NSMutableArray *)getList:(NSString *)_xml
{
    _xml = [StringUtil getXMLFormatedAttributeIncludeTag:_xml :@"MailList"];
    
    GDataXMLDocument *doc = [[[GDataXMLDocument alloc] initWithXMLString:_xml  options:0 error:nil]autorelease];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"MailInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        MailInfoModel *m = [[MailInfoModel alloc]init];
        GDataXMLElement *MAILGUID = [[arr elementsForName:@"MAILGUID"] objectAtIndex:0];
        m.MAILGUID = [MAILGUID stringValue];
        
        GDataXMLElement *FROMDISPNAME = [[arr elementsForName:@"FROMDISPNAME"] objectAtIndex:0];
        m.FROMDISPNAME = [FROMDISPNAME stringValue];
        
        GDataXMLElement *ToUserDispNameList = [[arr elementsForName:@"ToUserDispNameList"] objectAtIndex:0];
        m.ToUserDispNameList = [ToUserDispNameList stringValue];
        
        GDataXMLElement *SecretUserDispNameList = [[arr elementsForName:@"SecretUserDispNameList"] objectAtIndex:0];
        m.SecretUserDispNameList = [SecretUserDispNameList stringValue];
        
        GDataXMLElement *ChaoSongUserDispNameList = [[arr elementsForName:@"ChaoSongUserDispNameList"] objectAtIndex:0];
        m.ChaoSongUserDispNameList = [ChaoSongUserDispNameList stringValue];
        
        GDataXMLElement *Subject = [[arr elementsForName:@"Subject"] objectAtIndex:0];
        m.Subject = [Subject stringValue];
        
        GDataXMLElement *MailContent = [[arr elementsForName:@"MailContent"] objectAtIndex:0];
        m.MailContent = [MailContent stringValue];
        
        GDataXMLElement *SENDTIME = [[arr elementsForName:@"SENDTIME"] objectAtIndex:0];
        m.SENDTIME = [SENDTIME stringValue];
        
        GDataXMLElement *HasAttach = [[arr elementsForName:@"HasAttach"] objectAtIndex:0];
        m.HasAttach = [HasAttach stringValue];
        
        GDataXMLElement *IsAllSign = [[arr elementsForName:@"IsAllSign"] objectAtIndex:0];
        m.IsAllSign = [IsAllSign stringValue];
        
        GDataXMLElement *haveread = [[arr elementsForName:@"haveread"] objectAtIndex:0];
        m.haveread = [haveread stringValue];
        
        [listmp addObject:m];
        [m release];
    }
    
    return [listmp autorelease];
}

@end
